package com.jackeysun.app_common

import android.content.Intent
import android.content.res.Resources
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.lifecycle.lifecycleScope
import com.jackeysun.app_common.databinding.ActivityMainBinding
import com.jackeysun.common.ImageHandlerSelf
import com.jackeysun.common.showRich
import kotlinx.coroutines.launch


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val mainBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(mainBinding.root)

        lifecycleScope.launch {
            mainBinding.tv.showRich(DataSource.html, "img", ImageHandlerSelf(this@MainActivity,
                Resources.getSystem().displayMetrics.widthPixels))
            mainBinding.tv2.showRich(DataSource.img, "img", ImageHandlerSelf(this@MainActivity,
                Resources.getSystem().displayMetrics.widthPixels))
        }
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_util, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == R.id.recyclerview) {
            startActivity(Intent(this@MainActivity, MainActivity2::class.java))
            return true
        }
        if (item.itemId == R.id.activityManager) {
            startActivity(Intent(this@MainActivity, MainActivity3::class.java))
            return true
        }
        return super.onOptionsItemSelected(item)
    }
}